package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.activity.langyabang.config.LangYaBangConfig;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.langyabang.LangYaBangMgr;

import java.util.ArrayList;

public class LangYaBangRecycleStrategy extends AbstractItemRecycleStrategy {

    @Override
    public void markNeedRecycleItem() {
        LangYaBangConfig config = LangYaBangMgr.getConfig();
        if (config == null){
            return;
        }
        ActivityInfo activityInfo = LangYaBangMgr.getActivityInfo();
        if (activityInfo == null){
            return;
        }
        long recycleTime = activityInfo.getEndShowTime() * 1000L + gapTime;
        //暂时只有一个线索道具会被清空
        ActivityItemRecycleMgr.addRecycleItemData(config.getCaseClueItemId(), activityType, 1, recycleTime, new ArrayList<>());
        ActivityItemRecycleMgr.addRecycleItemData(config.getTemporaryTokenId(), activityType, 1, recycleTime, new ArrayList<>());
    }


    @Override
    public boolean isActivityRunning() {
        ActivityInfo activityInfo = LangYaBangMgr.getActivityInfo();
        return ActivityMgr.activityInTime(activityInfo);
    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.LangYaBang.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        if (data.getRecycleType() == 1){
            int itemId = data.getItemId();
            UserBagItem userBagItem = getUserBagItem(userId, itemId);
            if (userBagItem != null && userBagItem.getNum() > 0) {
                removeItem(userBagItem);
            }
        }
    }

}
